import $http from '@/utils/request.js';



export const getSwiperRecord = (param) => {
  return $http.get("/record/card", param)
}

export const getRecord = (param) => {
  return $http.get("/record/map", param)
}

export const getRecordDetail = (param) => {
  return $http.get(`/record/${param}`)
}



export const getRank = (param) => {
  return $http.get("/record/rank", param)
}


export const postRecord = (param) => {
  return $http.post("/record", param)
}


export const uploadPhoto = (param) => {
  return $http.post("/map/upload_photo", param)
}

export const putUserInfo = (param) => {
  return $http.put("/user/update", param)
}

export const getUserInfo = (param) => {
  return $http.get("/user/info", param)
}

export const getAssetsInfo = (param) => {
  return $http.get("/user/assets", param)
}

export const getOwnList = (param) => {
  return $http.get("/order/list", param)
}

export const createShipment = (param) => {
  return $http.post("/shipment/create", param)
}




export const getQrImg = (param) => {
  return $http.get("/gift/qrcode", param, "arraybuffer")
}

//检查cdk是否兑换
export const cdkcheck = (id) => {
  return $http.get("/order/getById/"+id)
}
//礼物cdk兑换
export const giftExchange = (param) => {
  return $http.post("/order/finish", {
    "orderId": param
  })
}
export const getShipment = () => {
  return $http.get("/shipment/list" )
}

//根据cdk查看兑换信息
export const getGiftExchange = (param) => {
  return $http.get("/order/getByCDK", {
    "cdk": param
  })
}

//用于生成打卡cdk（限管理）
export const getCdk = (param) => {
  return $http.get("/map/getcdk", param)
}







//上传文件
export const uploadFile = (e) => {
  return new Promise((resolve, reject) => {
    
    let shenai_userToken = wx.getStorageSync('shenai_userToken');
    let filePath=null;
    if(e.tempFilePaths) filePath = e.tempFilePaths[0];
    else filePath =e;
    console.log("filePath",filePath);
    if (shenai_userToken)

      wx.cloud.uploadFile({
        cloudPath: "shenai/" + new Date().getTime().toString() + Math.floor(Math.random() * 100000).toString() +
          '.png', // 对象存储路径，根路径直接填文件名，文件夹例子 test/文件名，不要 / 开头
        filePath, // 微信本地文件，通过选择图片，聊天文件等接口获取
        config: {
          env: 'prod-2gqzz1rq19c530a4' // 微信云托管环境ID
        },
        success: (res) => {

          // this.uploadInfo.photo = data.data;


          let data = res.fileID;



          // getFileUrl(data).then(Urlres=>{
          //   resolve(Urlres);
          // })
          resolve(data);

          //  let obj = {image:res.fileID,photo_check_trace_id:''};
          // console.log("postPhotoCheck外");
          // postPhotoCheck(res.fileID,scene).then(checkRes=>{
          //   console.log("checkRes");
          //   console.log(checkRes);
          //   obj.photo_check_trace_id=checkRes.data.data.trace_id
          //   resolve(obj);
          // })
        },


        fail: (res) => {
          reject(res);
        }
      })


  })
}

//获取图片临时链接
export const getFileUrl = (fileID) => {
  return new Promise((resolve, reject) => {

    wx.cloud.getTempFileURL({
      fileList: [fileID], // 文件唯一标识符 cloudID, 可通过上传文件接口获取
      success: (res) => {
        let data = res.fileList[0].tempFileURL;
        console.log(res.fileList[0].tempFileURL)
        console.log(res)
        resolve(data);
      },
      fail: (res) => {
        reject("");
      }

    })

  })
}


export const postPhotoCheck = (image_url, scene) => {
  return $http.post("/map/user_photo_check", {
    image_url,
    scene
  })
}